package cn.com.hp.feature.service.impl;

import cn.com.hp.feature.domain.dto.SysUserInfoDTO;
import cn.com.hp.feature.domain.entity.SysUserInfo;
import cn.com.hp.feature.domain.vo.PageVO;
import cn.com.hp.feature.mapper.SysUserInfoMapper;
import cn.com.hp.feature.service.ISysUserInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: hjz
 * @since: 2022/8/27
 * @description:
 */
@Service
public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUserInfo> implements ISysUserInfoService {

    @Autowired
    private SysUserInfoMapper sysUserInfoMapper;

    @Override
    public List<SysUserInfo> selectList(SysUserInfo userInfo) {
        return sysUserInfoMapper.selectUserList(userInfo);
    }

    @Override
    public PageVO<SysUserInfo> selectUserPage(SysUserInfoDTO sysUserInfo) {
        PageVO<SysUserInfo> data = new PageVO();

        //默认分页数据是第一页，每页10条
        int current = sysUserInfo.getPage() == null ? 1 : sysUserInfo.getPage();
        int size = sysUserInfo.getRow() == null ? 10 : sysUserInfo.getRow();
        Page<SysUserInfo> page = new Page<>(current, size);
        //获取分页数据
        Page<SysUserInfo> pages = sysUserInfoMapper.selectPageByRequest(page, sysUserInfo);
        data.setList(pages.getRecords());
        data.setPage(pages.getCurrent());
        data.setPageSize(pages.getSize());
        data.setTotal(pages.getTotal());
        return data;
    }
}
